<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>宏任务微任务</title>
</head>
<body>
<!-- 
    宏任务：script(整体代码)、setTimeout、setInterval、setImmediate、I/O、UI rendering
    微任务：promise.then.catch.finally、Object observer、MutationObserver
    任务的优先级：微任务优先于宏任务 process.nextTick > promise.then > setTimeout > setImmediate

    微任务是跟屁虫，一直跟着当前宏任务后面，代码执行到一个微任务就跟上，一个接一个
 -->
</body>
<script>
    // setImmediate(()=>{
    //     console.log('setImmediate')
    // })
    // fn()
    console.log('3')
    setTimeout(()=>{
        console.log('setTimeout1')
    },100)
    setTimeout(()=>{
        console.log('setTimeout2')
    },0)
    console.log('5')
    new Promise((resolve,reject)=>{
        console.log('6')
        reject()
    }).then(()=>{
        console.log('then1')
    }).then(()=>{
        console.log('then2')
    }).catch(()=>{
        console.log('catch1')
    })
    new Promise(resolve=>{
        resolve()
    }).then(()=>{
        console.log('3')
        // return Promise.reject()
    }).catch(()=>{
        console.log('catch')
    })
    // async function fn(){
    //     console.log('async fn')
    //     await Promise.resolve().then(()=>{
    //         console.log('9')
    //     })
    //     console.log('2')
    // }
   
    // process.nextTick(()=>{
    //     console.log('process nextTick')
    // })

</script>
</html>